from django.db import models

# Create your models here.
from DjangoUeditor.models import UEditorField


class Category(models.Model):
    category_name = models.CharField(max_length=50)

    def __str__(self):
        return self.category_name

    class Meta:
        verbose_name_plural = '分类'


class Tag(models.Model):
    tag_name = models.CharField(max_length=20)

    def __str__(self):
        return self.tag_name

    class Meta:
        verbose_name_plural = '标签'


class Post(models.Model):
    title = models.CharField('标题', max_length=50)
    content = UEditorField('内容', width=1200, height=800)
    create_time = models.DateField('创建时间', auto_now_add=True)
    visitor_num = models.IntegerField('浏览量', default=0)
    category = models.ForeignKey(Category)
    tags = models.ManyToManyField(Tag)
    describe = models.TextField('描述', max_length=1000)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = '文章'

    def tag_(self):
        return '/'.join([i for i in self.tags.all()])

    tag_.short_description = '标签'

    def category_(self):
        return self.category.category_name

    category_.short_description = '分类'
